import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from '../views/home/index.vue'
import Kind from '../views/kind/index.vue'
import Cart from '../views/cart/index.vue'
import User from '../views/user/index.vue'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch((err) => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/kind',
    name: 'kind',
    component: Kind
  },
  {
    path: '/cart',
    name: 'cart',
    component: Cart
  },
  {
    path: '/user',
    name: 'user',
    component: User
  },
  {
    path: '/detail/:proid',
    name: 'detail',
    component: () => import(/* webpackChunkName: 'detail' */'../views/detail/index.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/register',
    name: '/register',
    component: () => import(/* webpackChunkName: 'user' */'../views/register/index.vue'),
    redirect: '/register/step1',
    meta: {
      hidden: true
    },
    children: [
      {
        path: 'step1',
        name: 'registerStep1',
        component: () => import(/* webpackChunkName: 'user' */'../views/register/step1.vue'),
        meta: { hidden: true }
      },
      {
        path: 'step2',
        name: 'registerStep2',
        component: () => import(/* webpackChunkName: 'user' */'../views/register/step2.vue'),
        meta: { hidden: true }
      },
      {
        path: 'step3',
        name: 'registerStep3',
        component: () => import(/* webpackChunkName: 'user' */'../views/register/step3.vue'),
        meta: { hidden: true }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: 'user' */'../views/login/index.vue'),
    meta: { hidden: true }
  },
  {
    path: '*',
    component: () => import(/* webpackChunkName: 'error' */'../views/error/notFound.vue')
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
